//
//  YHPJTableViewCell.m
//  yonghu
//
//  Created by mac on 2018/3/20.
//  Copyright © 2018年 com.DJS. All rights reserved.
//

#import "YHPJTableViewCell.h"

@implementation YHPJTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(CGFloat)creatView{
    self.backgroundColor=_LightGrey;
    UIView *view=[UIView new];
    [self addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5);
        make.right.mas_equalTo(-5);
        make.top.mas_equalTo(10);
        make.bottom.mas_equalTo(0);
    }];
    view.backgroundColor=[UIColor whiteColor];
    view.layer.cornerRadius=5;
        

    UIImageView *imageView=[UIImageView new];
    [view addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(10);
        make.height.width.mas_equalTo(40);
    }];
    imageView.layer.masksToBounds=YES;
    imageView.layer.cornerRadius=20;
    NSString *user_icon=[_dic objectForKey:@"user_icon"];
    user_icon=[NSString stringWithFormat:@"%@%@",_addressUrl,user_icon];
    NSURL *url=[NSURL URLWithString:user_icon];
    [imageView sd_setImageWithURL:url];
    
    UILabel *nameLabel=[UILabel new];
    [view addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(imageView.mas_right).mas_equalTo(10);
        make.top.mas_equalTo(imageView);
    }];
    nameLabel.text=[_dic objectForKey:@"user_nickname"];
    nameLabel.font=[UIFont systemFontOfSize:16];
    nameLabel.textColor=ColorWithRGB(49, 49, 49);
    
    UILabel *nameLabel2=[UILabel new];
    [view addSubview:nameLabel2];
    [nameLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(imageView.mas_right).mas_equalTo(10);
        make.bottom.mas_equalTo(imageView);
    }];
    nameLabel2.text=[_dic objectForKey:@"evaluate_time_text"];
    nameLabel2.font=[UIFont systemFontOfSize:16];
    nameLabel2.textColor=ColorWithRGB(149, 149, 149);
    
    
    NSString *evaluate_content=[_dic objectForKey:@"evaluate_content"];
    CGSize size=[ZQTools getNSStringSize:evaluate_content andViewWight:_mainW-40 andFont:17];
    
    
    
    UILabel *lable12=[UILabel new];
    [view addSubview:lable12];
    [lable12 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(imageView);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(imageView.mas_bottom).mas_equalTo(10);
        make.height.mas_equalTo(size.height);
    }];
    lable12.textColor=ColorWithRGB(79, 79, 79);
    lable12.text=evaluate_content;
    lable12.font=[UIFont systemFontOfSize:17];
    lable12.numberOfLines=0;
    
    UIView *xianView=[UIView new];
    [view addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(lable12.mas_bottom).mas_equalTo(10);
        make.height.mas_equalTo(1);
    }];
    xianView.backgroundColor=_LightGrey;

    
    NSNumber *evaluate_score=[_dic objectForKey:@"evaluate_score"];
    int typeNum2=evaluate_score.doubleValue*10;
    int typeNum=typeNum2%10;
    int index=5-evaluate_score.floatValue;
    
    UILabel *pingFen=[UILabel new];
    [view addSubview:pingFen];
    [pingFen mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(xianView.mas_bottom).mas_equalTo(10);
        make.left.mas_equalTo(10);
    }];
    pingFen.text=@"评分:";
    pingFen.textColor=ColorWithRGB(149, 149, 149);
    pingFen.font=[UIFont systemFontOfSize:16];


        for (int j=0; j<5; j++) {

            UIImageView *xingImage=[UIImageView new];
            [view addSubview:xingImage];
            [xingImage mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(pingFen.mas_right).mas_equalTo(10+25*j);
                make.height.width.mas_equalTo(20);
                make.centerY.mas_equalTo(pingFen);
            }];

            if (typeNum>0) {
                if (j>index) {
                    xingImage.image=[UIImage imageNamed:@"评分2"];
                }
                if (j==index) {
                    xingImage.image=[UIImage imageNamed:@"评分3"];
                }
                if (j<index) {
                    xingImage.image=[UIImage imageNamed:@"评分1"];
                }
            }
            else{
                if (j>index) {
                    xingImage.image=[UIImage imageNamed:@"评分2"];
                }
                else{
                    xingImage.image=[UIImage imageNamed:@"评分1"];
                }
            }
        }

    return 130+size.height;
}

@end
